﻿using AbpProjectTemplate.Components.Payments.Event;
using System;
using System.Threading.Tasks;

namespace AbpProjectTemplate.Components.Payments
{
    /// <summary>
    /// 定义支付API，用于发起支付、退款、服务订单等操作
    /// </summary>
    public interface IPaymentApi
    {
        /// <summary>
        /// 支付方式
        /// </summary>
        PaymentType PaymentType { get; }

        #region 请求
        /// <summary>
        /// 创建支付通知的回复消息
        /// </summary>
        /// <param name="success"></param>
        /// <returns></returns>
        string CreateNotifyResponseMessage(bool success);
        /// <summary>
        /// 发起支付下订单
        /// </summary>
        /// <param name="orderId">商家订单号</param>
        /// <param name="amount">支付金额</param>
        /// <param name="body">订单描述</param>
        /// <param name="extensionData">扩展数据</param>
        Task<string> CreateOrderAsync(string orderId, decimal amount, string body, string extensionData = null);
        /// <summary>
        /// 发起退款
        /// </summary>
        /// <param name="orderNo">订单号</param>
        /// <param name="orderAmount">订单金额</param>
        /// <param name="refundOrderNo">退款订单号</param>
        /// <param name="refundAmount">退款金额</param>
        /// <param name="desc">退款说明</param>
        Task<bool> RefundAsync(string orderNo, decimal orderAmount, string refundOrderNo, decimal refundAmount, string desc);
        /// <summary>
        /// 创建服务订单
        /// </summary>
        /// <param name="orderNo">订单号</param>
        /// <param name="serviceIntroduction">服务信息</param>
        /// <param name="riskFundName">风险金名称，如押金</param>
        /// <param name="riskFundAmount">风险金金额</param>
        /// <param name="startLocation">开始服务地点（选填）</param>
        /// <param name="startTime">开始服务时间（选填）</param>
        /// <returns></returns>
        Task<string> CreateServiceOrderAsync(string orderNo, string serviceIntroduction, string riskFundName, decimal riskFundAmount, string startLocation = null, DateTime? startTime = null);
        /// <summary>
        /// 完结服务订单
        /// </summary>
        /// <param name="orderNo">订单号</param>
        /// <param name="paymentFinishTicket">完成服务的票据</param>
        /// <param name="amount">总金额</param>
        /// <param name="serviceName">服务名称</param>
        /// <param name="serviceDesc">服务描述</param>
        /// <param name="endTime">结束时间，不填则为当前时间</param>
        /// <param name="endLocation">结束地点</param>
        Task<bool> CompleteServiceOrderAsync(string orderNo, string paymentFinishTicket, decimal amount, string serviceName, string serviceDesc, DateTime? endTime = null, string endLocation = null);
        /// <summary>
        /// 取消服务订单
        /// </summary>
        /// <param name="orderNo">订单号</param>
        /// <param name="paymentFinishTicket">完成服务的票据</param>
        /// <param name="reason">取消原因</param>
        Task<bool> CannelServiceOrderAsync(string orderNo, string paymentFinishTicket, string reason);
        /// <summary>
        /// 转账给用户返回交易号
        /// </summary>
        /// <param name="orderNo">订单号</param>
        /// <param name="openId">用户的openid</param>
        /// <param name="amount">金额</param>
        /// <param name="desc">描述</param>
        /// <param name="trueName">真实姓名</param>
        /// <param name="checkName">是否检查真实姓名，如果为true trueName必填</param>
        /// <returns>交易号</returns>
        Task<string> TransferAsync(string orderNo, string openId, decimal amount, string desc, string trueName = null, bool checkName = false);
        #endregion

        #region 通知处理
        /// <summary>
        /// 处理支付通知处理
        /// </summary>
        Task<PayNotifyEventData> PayNotifyHandleAsync();
        /// <summary>
        /// 退款通知处理
        /// </summary>
        Task<RefundNotifyEventData> RefundNotifyHandleAsync();
        /// <summary>
        /// 服务订单确认处理
        /// </summary>
        Task<ServiceConfimNotifyEventData> ServiceConfirmNotifyHandleAsync();
        /// <summary>
        /// 服务订单完成通知
        /// </summary>
        Task<ServiceCompleteNotifyEventData> ServiceCompleteNotifyHanleAsync();
        #endregion
    }
}
